package com.maotai.util;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.http.client.config.RequestConfig;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.maotai.bean.MaotaiWebCookie;
import com.maotai.bean.ProductDetail;

public class HttpClientUtilGroup {
	
	public HttpClientUtilGroup() {
	}

	public MaotaiWebCookie httpIndexGroup(MaotaiWebCookie mwc, RequestConfig config,Map<String, Object> zhanghao) throws Exception {
		//主要用来访问主页�?
		//用于预约，登录，抢购�?
		
		HttpClientUtilNew httpNew = HttpClientUtilNew.getInstance();
		
		
		String indexUrl = "https://www.emaotai.cn/";
		mwc = httpNew.sendHttpGetProxyIndex(indexUrl, mwc, config, "");
		
		String userId = zhanghao.get("memberId")+"";
		String checkVersionUrl = "https://i.emaotai.cn/smartsales-mgmt-application/api/v1/smartsales/mgmt/protocol/check/version?channelCode=01&protocolType=0&userId="+userId+"&appCode=1&_t="+System.currentTimeMillis();
		mwc = httpNew.sendHttpGetProxy(checkVersionUrl, mwc, config, indexUrl);
		
		String qrcodeUrl = "https://i.emaotai.cn/smartsales-sys-application/api/v1/sys/app/manager/qrcode/get?byname=o2o&appCode=1&_t="+System.currentTimeMillis();
		mwc = httpNew.sendHttpGetProxy(qrcodeUrl, mwc, config, indexUrl);
		
		String type2url = "https://i.emaotai.cn/smartsales-trade-application/api/v1/smartsales/trade/mall/sub/list?type2&type=2&appCode=1&_t="+System.currentTimeMillis();
		mwc = httpNew.sendHttpGetProxy(type2url, mwc, config, indexUrl);
		
		String linkurl = "https://i.emaotai.cn/smartsales-trade-application/api/v1/smartsales/trade/mall/link/list?appCode=1&_t="+System.currentTimeMillis();
		mwc = httpNew.sendHttpGetProxy(linkurl, mwc, config, indexUrl);
		
		String type3url = "https://i.emaotai.cn/smartsales-trade-application/api/v1/smartsales/trade/mall/sub/list?type3&type=3&appCode=1&_t="+System.currentTimeMillis();
		mwc = httpNew.sendHttpGetProxy(type3url, mwc, config, indexUrl);
		
		String type1url = "https://i.emaotai.cn/smartsales-trade-application/api/v1/smartsales/trade/mall/sub/list?type1&type=1&appCode=1&_t="+System.currentTimeMillis();
		mwc = httpNew.sendHttpGetProxy(type1url, mwc, config, indexUrl);
		
		String accountDetailUrl = "https://i.emaotai.cn/yundt-application-trade-core/api/v1/yundt/trade/member/account/detail/get?appCode=1&_t="+System.currentTimeMillis();
		mwc = httpNew.sendHttpGetProxy(accountDetailUrl, mwc, config, indexUrl);
		
		String cartItemUrl = "https://i.emaotai.cn/yundt-application-trade-core/api/v1/yundt/trade/cart/item/count?appCode=1&_t="+System.currentTimeMillis();
		mwc = httpNew.sendHttpGetProxy(cartItemUrl, mwc, config, indexUrl);
		
		String mymessageUrl = "https://i.emaotai.cn/smartsales-trade-application/api/v1/smartsales/trade/message/mymessage/list?pageNum=1&pageSize=10&status=0&order=desc&appCode=1&_t="+System.currentTimeMillis();
		mwc = httpNew.sendHttpGetProxy(mymessageUrl, mwc, config, indexUrl);
		
		//首页访问结束
		return mwc;
	}
	public MaotaiWebCookie httpDetailGroup(MaotaiWebCookie mwc, RequestConfig config,Map<String, Object> zhanghao) throws Exception {
		//主要用来访问商品详细页面
		//用于预约，抢购等
		System.out.println(zhanghao.get("code")+"---"+"进入商品详细页");
		HttpClientUtilNew httpNew = HttpClientUtilNew.getInstance();
		String memberId = zhanghao.get("memberId")+"";
		
		String detailUrl = "https://www.emaotai.cn/smartsales-b2c-web-pc/details/"+ProductDetail.ITEMID+"-"+ProductDetail.SHOPID+".html?skuId="+ProductDetail.GOODSID;
		mwc = httpNew.sendHttpGetProxyIndex(detailUrl, mwc, config, "");
		
		String qrcodeUrl = "https://i.emaotai.cn/smartsales-sys-application/api/v1/sys/app/manager/qrcode/get?byname=o2o&appCode=1&_t="+System.currentTimeMillis();
		mwc = httpNew.sendHttpGetProxy(qrcodeUrl, mwc, config, detailUrl);
		
		String accountDetailUrl = "https://i.emaotai.cn/yundt-application-trade-core/api/v1/yundt/trade/member/account/detail/get?appCode=1&_t="+System.currentTimeMillis();
		mwc = httpNew.sendHttpGetProxy(accountDetailUrl, mwc, config, detailUrl);
		
		String deliveryListUrl = "https://i.emaotai.cn/yundt-application-trade-supporting/api/v1/yundt/trade/logistics/delivery/list?code=&shopId="+ProductDetail.SHOPID+"&itemId="+ProductDetail.ITEMID+"&skuId="+ProductDetail.GOODSID+"&appCode=1&_t="+System.currentTimeMillis();
		mwc = httpNew.sendHttpGetProxy(deliveryListUrl, mwc, config, detailUrl);
		
		String cartItemUrl = "https://i.emaotai.cn/yundt-application-trade-core/api/v1/yundt/trade/cart/item/count?appCode=1&_t="+System.currentTimeMillis();
		mwc = httpNew.sendHttpGetProxy(cartItemUrl, mwc, config, detailUrl);
		
		String mymessageUrl = "https://i.emaotai.cn/smartsales-trade-application/api/v1/smartsales/trade/message/mymessage/list?pageNum=1&pageSize=10&status=0&order=desc&appCode=1&_t="+System.currentTimeMillis();
		mwc = httpNew.sendHttpGetProxy(mymessageUrl, mwc, config, detailUrl);
		
		String bookmarkItemUrl = "https://i.emaotai.cn/yundt-application-trade-core/api/v1/yundt/trade/member/bookmark/item/exist?skuId="+ProductDetail.GOODSID+"&itemId="+ProductDetail.ITEMID+"&shopId="+ProductDetail.SHOPID+"&appCode=1&_t="+System.currentTimeMillis();
		mwc = httpNew.sendHttpGetProxy(bookmarkItemUrl, mwc, config, detailUrl);
		
		String activityPostUrl = "https://i.emaotai.cn/yundt-application-trade-core/api/v1/yundt/trade/item/activity?appCode=1&_t="+System.currentTimeMillis();
		Map<String, String> maps = new HashMap<String, String>();
		List<String> list = new ArrayList<String>();
		list.add(ProductDetail.ITEMID);
		maps.put("itemIds", list.toString());
		mwc = httpNew.sendHttpPostProxy(activityPostUrl, mwc, maps, config, detailUrl);
		System.out.println(zhanghao.get("code")+"---"+"进入商品详细页"+"777");
		String skugetUrl = "https://i.emaotai.cn/yundt-application-trade-core/api/v1/yundt/trade/item/sku/get?shopId="+ProductDetail.SHOPID+"&itemId="+ProductDetail.ITEMID+"&skuId="+ProductDetail.GOODSID+"&appCode=1&_t="+System.currentTimeMillis();
		mwc = httpNew.sendHttpGetProxy(skugetUrl, mwc, config, detailUrl);
		
		String goodsDetailInfoUrl = "https://i.emaotai.cn/cmaotai-application-ysdt/api/v1/ysdt/activity/goods/detail/info?goodsId="+ProductDetail.GOODSID+"&appCode=1&_t="+System.currentTimeMillis();
		mwc = httpNew.sendHttpGetProxy(goodsDetailInfoUrl, mwc, config, detailUrl);
		
		//{"data":null,"resultCode":-1,"resultMsg":"系统错误"}
		String userInfoUrl = "https://i.emaotai.cn/cmaotai-application-ysdt/api/v1/ysdt/activity/user/info?goodsId="+ProductDetail.GOODSID+"&memberId="+memberId+"&appCode=1&_t="+System.currentTimeMillis();
		mwc = httpNew.sendHttpGetProxy(userInfoUrl, mwc, config, detailUrl);
		
		//评论
		String commentItemListUrl = "https://i.emaotai.cn/yundt-application-trade-supporting/api/v1/yundt/trade/comment/item/list?pageNum=1&shopId="+ProductDetail.SHOPID+"&itemId="+ProductDetail.ITEMID+"&level=0&appCode=1&_t="+System.currentTimeMillis();
		mwc = httpNew.sendHttpGetProxy(commentItemListUrl, mwc, config, detailUrl);
		
		String commentItemStatisticsUrl = "https://i.emaotai.cn/yundt-application-trade-supporting/api/v1/yundt/trade/comment/item/statistics?itemId="+ProductDetail.ITEMID+"&shopId="+ProductDetail.SHOPID+"&appCode=1&_t="+System.currentTimeMillis();
		mwc = httpNew.sendHttpGetProxy(commentItemStatisticsUrl, mwc, config, detailUrl);
		
		return mwc;
	}
	public MaotaiWebCookie httpDealGroup(MaotaiWebCookie mwc, RequestConfig config,Map<String, Object> zhanghao) throws Exception {
		//结算页面
		//用于抢购�?
		System.out.println(zhanghao.get("code")+"---"+"进入商品提交页");
		String dealUrl = "https://www.emaotai.cn/smartsales-b2c-web-pc/deal?isStatic=0";
		HttpClientUtilNew httpNew = HttpClientUtilNew.getInstance();
		
		String detailUrl = "https://www.emaotai.cn/smartsales-b2c-web-pc/details/"+ProductDetail.ITEMID+"-"+ProductDetail.SHOPID+".html?skuId="+ProductDetail.GOODSID;
		mwc = httpNew.sendHttpGetProxyIndex(dealUrl, mwc, config, detailUrl);
		
		String addressListUrl = "https://i.emaotai.cn/yundt-application-trade-core/api/v1/yundt/trade/member/address/list?appCode=1&_t="+System.currentTimeMillis();
		mwc = httpNew.sendHttpGetProxy(addressListUrl, mwc, config, dealUrl);
		
		String activityPostUrl = "https://i.emaotai.cn/yundt-application-trade-core/api/v1/yundt/trade/item/activity?appCode=1&_t="+System.currentTimeMillis();
		Map<String, String> maps = new HashMap<String, String>();
		List<String> list = new ArrayList<String>();
		list.add(ProductDetail.ITEMID);
		maps.put("itemIds", list.toString());
		mwc = httpNew.sendHttpPostProxy(activityPostUrl, mwc, maps, config, dealUrl);
		
		String consumegetUrl = "https://i.emaotai.cn/yundt-application-trade-core/api/v1/yundt/trade/member/point/consume/get?appCode=1&_t="+System.currentTimeMillis();
		mwc = httpNew.sendHttpGetProxy(consumegetUrl, mwc, config, dealUrl);
		
		String accountDetailUrl = "https://i.emaotai.cn/yundt-application-trade-core/api/v1/yundt/trade/member/account/detail/get?appCode=1&_t="+System.currentTimeMillis();
		mwc = httpNew.sendHttpGetProxy(accountDetailUrl, mwc, config, dealUrl);
		
		//全国地区有点多，有必要的话可以删�?
//		String areaListUrl = "https://i.emaotai.cn/smartsales-sys-application/api/v1/sys/area/list?appCode=1&_t="+System.currentTimeMillis();
//		mwc = httpNew.sendHttpGetProxy(areaListUrl, mwc, config, dealUrl);
		
		//获取�?��下拉框：快�?
		String deliverygetUrl = "https://i.emaotai.cn/yundt-application-trade-core/api/v1/yundt/trade/order/delivery/get?appCode=1&_t="+System.currentTimeMillis();
		//shopItems:[{"settletMent":[{"skuId":"1187543793848641543","itemId":"1187543793837107201","shopId":"1173773178264259584","quantity":"1","price":"1489.00"}],"shopId":"1173773178264259584"}]
		JSONArray settletMentArry = new JSONArray();
		JSONObject productItem = new JSONObject();
		JSONObject shopItemsJson = new JSONObject();
		
		productItem.put("skuId", ProductDetail.GOODSID);
		productItem.put("itemId", ProductDetail.ITEMID);
		productItem.put("shopId", ProductDetail.SHOPID);
		productItem.put("quantity", ProductDetail.QUANTITY);
		productItem.put("price", ProductDetail.PRICE);
		settletMentArry.add(productItem);
		
		shopItemsJson.put("settletMent", settletMentArry);
		shopItemsJson.put("shopId", ProductDetail.SHOPID);
		System.out.println(productItem);
		
		list.clear();
		maps.clear();
		list.add(shopItemsJson.toString());
		maps.put("shopItems", list.toString());
		System.out.println(list.toString());
		mwc = httpNew.sendHttpPostProxy(deliverygetUrl, mwc, maps, config, dealUrl);
		
		String cartItemCountUrl = "https://i.emaotai.cn/yundt-application-trade-core/api/v1/yundt/trade/cart/item/count?appCode=1&_t="+System.currentTimeMillis();
		mwc = httpNew.sendHttpGetProxy(cartItemCountUrl, mwc, config, dealUrl);
		
		String mymessageListUrl = "https://i.emaotai.cn/smartsales-trade-application/api/v1/smartsales/trade/message/mymessage/list?pageNum=1&pageSize=10&status=0&order=desc&appCode=1&_t="+System.currentTimeMillis();
		mwc = httpNew.sendHttpGetProxy(mymessageListUrl, mwc, config, dealUrl);
		
		String orderListUrl = "https://i.emaotai.cn/yundt-application-trade-core/api/v1/yundt/trade/promotion/order/list?appCode=1&_t="+System.currentTimeMillis();
		maps.put("itemDetails", settletMentArry.toJSONString());
		mwc = httpNew.sendHttpPostProxy(orderListUrl, mwc, maps, config, dealUrl);
		
		
		String costgetUrl = "https://i.emaotai.cn/yundt-application-trade-core/api/v1/yundt/trade/order/delivery/cost/get?appCode=1&_t="+System.currentTimeMillis();
		list.clear();
		maps.clear();
		maps.put("shops", list.toString());
		mwc = httpNew.sendHttpPostProxy(costgetUrl, mwc, maps, config, dealUrl);
		
		//发票
		String invoiceListCacheUrl = "https://i.emaotai.cn/yundt-application-trade-supporting/api/v1/yundt/trade/invoice/list/cache?shopId="+ProductDetail.SHOPID+"&appCode=1&_t="+System.currentTimeMillis();
		mwc = httpNew.sendHttpGetProxy(invoiceListCacheUrl, mwc, config, dealUrl);
		//查了2次发票，不知道为�?��
		
		
		return mwc;
	}
	public MaotaiWebCookie httpDealGroup741(MaotaiWebCookie mwc, RequestConfig config,Map<String, Object> zhanghao) throws Exception {
		//结算页面
		//用于抢购�?
		System.out.println(zhanghao.get("code")+"---"+"进入商品提交页");
		String memberId = zhanghao.get("memberId")+"";
		String dealUrl = "https://www.emaotai.cn/smartsales-b2c-web-pc/deal?isStatic=1";
		HttpClientUtilNew httpNew = HttpClientUtilNew.getInstance();
		
		String detailUrl = "https://www.emaotai.cn/smartsales-b2c-web-pc/details/"+ProductDetail.ITEMID+"-"+ProductDetail.SHOPID+".html?skuId="+ProductDetail.GOODSID;
		mwc = httpNew.sendHttpGetProxyIndex(dealUrl, mwc, config, detailUrl);
		
		String accountUrl = "https://i.emaotai.cn/yundt-application-trade-core/api/v1/yundt/trade/member/account/detail/get?appCode=1&_t="+System.currentTimeMillis();
		mwc = httpNew.sendHttpGetProxy(accountUrl, mwc, config, dealUrl);
		String userInfoUrl = "https://i.emaotai.cn/cmaotai-application-ysdt/api/v1/ysdt/activity/user/info?goodsId="+ProductDetail.GOODSID+"&memberId="+memberId+"&appCode=1&_t="+System.currentTimeMillis();
		mwc = httpNew.sendHttpGetProxy(userInfoUrl, mwc, config, dealUrl);
		String cachUrl = "https://i.emaotai.cn/yundt-application-trade-supporting/api/v1/yundt/trade/invoice/list/cache?shopId="+ProductDetail.SHOPID+"&appCode=1&_t="+System.currentTimeMillis();
		mwc = httpNew.sendHttpGetProxy(cachUrl, mwc, config, dealUrl);
		
		return mwc;
	}
	
	public MaotaiWebCookie httpSignUpGroup(MaotaiWebCookie mwc, RequestConfig config,Map<String, Object> zhanghao,String info) throws Exception {
		//提交预约页面
		//用于预约�?
		String signUpUrl = "https://www.emaotai.cn/smartsales-b2c-web-pc/sign/signUp?info="+info;
		HttpClientUtilNew httpNew = HttpClientUtilNew.getInstance();
		
		String detailUrl = "https://www.emaotai.cn/smartsales-b2c-web-pc/details/"+ProductDetail.ITEMID+"-"+ProductDetail.SHOPID+".html?skuId="+ProductDetail.GOODSID;
		mwc = httpNew.sendHttpGetProxyIndex(signUpUrl, mwc, config, detailUrl);
		
		//地址
		String addressListUrl = "https://i.emaotai.cn/yundt-application-trade-core/api/v1/yundt/trade/member/address/list?appCode=1&_t="+System.currentTimeMillis();
		mwc = httpNew.sendHttpGetProxy(addressListUrl, mwc, config, signUpUrl);
		
		//全国地区有点多，有必要的话可以删�?
		String areaListUrl = "https://i.emaotai.cn/smartsales-sys-application/api/v1/sys/area/list?appCode=1&_t="+System.currentTimeMillis();
		mwc = httpNew.sendHttpGetProxy(areaListUrl, mwc, config, signUpUrl);
		
		return mwc;
	}
}